export default {
    state: {
        mtarr: []
    },
    mutations: {
        add(state, item) {
            var bool = false
            item.num++
            for (var i = 0; i < state.mtarr.length; i++) {
                if (state.mtarr[i].id == item.id) {
                    bool = true
                }
            }
            if (bool == false) {
                state.mtarr.push(item)
            }
        },
        jian(state, item) {
            if (item.num > 0) {
                item.num--
            }
            for (var i = 0; i < state.mtarr.length; i++) {
                if (state.mtarr[i].num == 0) {
                    state.mtarr.splice(i, 1)
                }
            }
        }
    },
    getters: {
        dl(state) {
            var n = 0
            var pr=0
            state.mtarr.forEach(i => {
                n += i.num
                pr+=i.num*i.price
            })
            return [n,pr]
        }
    }
}